//created by: Justina Lee

Ext.define('MajorProjectSenchaTouch.controller.Main', {
    extend: 'Ext.app.Controller',
    requires: [
    'Ext.util.DelayedTask'
    ],
    config:{ 
        views: ['BookMarkedModule.BookMarked','ContactUsModule.ContactUs','LibraryUpdatesModule.LibraryUpdates', 'More', 'BookMarkedModule.BookMarkedDataview',
		'ExamPaperModule.ExamSearch', 'ExamPaperModule.ExamPapersLogin', 'ExamPaperModule.ExamResultInfoDisplay', 'NewArrivals.NewArrivals','FloorPlans.FloorPlans','AdditionalResources.addView',
		'FloorPlans.levelnine','MyAccountModule.MyAccountLogin','MyAccountModule.MyAccountMain','MyAccountModule.MyAccountRenew','SpinMeModule.SpinMe',
		'MyAccountModule.MyAccountReservation','NewArrivals.NewArrivalsSelectType', 'NewArrivals.NewArrivalsList','NewArrivals.NewArrivalsSort', 'SearchModule.DisplayResult', 'Main'],
        refs:{
            navView: 'mainNavView',
            announcements: 'basicsearchpanel',
            homeButton: 'button[action=goHome]',
            bookMarkedButton: 'button[action=goBookMarked]',
            contactUsButton: 'button[action=goContactUs]',
            libraryUpdatesButton: 'button[action=goLibraryUpdates]',
            mainexampaperBtn: 'button[action=goExamPaperpage]',
            mainmyaccBtn: 'button[action=goMyAccpage]',
            eResourcesButton: 'button[action=goEResourcespage]',
            advanceResultButton: 'button[action=goAdvanceSearchPan]',
            advanceResultPage: 'advancepage',
            openingHoursButton: 'button[action=goOpeningHours]',
            
            bookMarkedListPaging: '#bmListPaging',
            bookMarkedMainView: '#bookmarkedView',
			// Citation: 'button[action=goCitationPage]',
			// LibraryVideos: 'button[action=golibraryvideospage]',
			mainAddResourcesBtn: 'button[action=goAddResourcespage]',
            mainNewArrivalsBtn: 'button[action=goNewArrivalsPage]',
			floorplansbtn:'button[action = goFloorPlanspage]',
			
            mainPanel: '#mainPanel',
            mainBackButton: '#mainBackButton',
            homeSegmentedBtn : '#homeSegmentedBtn',
            moreList: 'moremenuDV',
			
			// My account
			myaccountlogin: 'myaccountlogin',
			// myaccountmain: 'myaccountmain',
			MALogin: 'button[action=goMyaccmain]',
			userfield: '#userfield',
			passfield: '#passfield',
			MALoan: 'button[action=goMyAccLoan]',
			MAReservation: 'button[action=goMyAccReservation]',
			MALogout: 'button[action=goMyAccLogin]',
			MARenew: 'button[action=doRenew]',
			// My account end
			RandomClick: 'button[action=getRandomFive]',
			
            ohSegmentedBtn: '#ohSegmentedBtn',
            openingHoursTermDV: 'openinghoursTermDV',
            ohMainPanel: 'openinghoursMainBody',

            additionalResources:'#additionalResources',

          //  floorplans: '#floorplans',
		  // Announcements
            announcementsListItem: 'announcementsPage',
		// new arrivals
		    newarrivalspage: 'newarrivalspage',
			// // NAresultselect : 'NAresultselect'
			// ,
			// selecttypeField: '#selecttypeField',
			// na1selectfiled: 'button[action=goNewArrivalSearchResult]',
            selectedfield: '#selecttypeField',
			sorterfield:'#newsorterField',
            resultListPage: 'newArrivalList',
           // searchResultPage: 'newarrivalspage',
			// searchResultPage: 'searchpage',
            resultRangeButton: '#resultrangeBtn',
			searchButton:'#resultsummaryBtn',
			basecon: '#basecon',
			prevNewArrivalBtn: 'button[action=getprevNewArrivalsResult]',
			nextNewArrivalBtn: 'button[action=getnextNewArrivalsResult]',
			nextResultsBtn: '#naviBtnNCusArrivals',
            prevResultsBtn: '#naviBtnPCusArrivals',
			// Exam Papers
			examlogin: '#examlogin',
			exLogin: 'button[action=goExamSearchpage]',
			userfieldexam: '#userfieldexam',
			passfieldexam: '#passfieldexam',
			examLogout: '#exLogout',
			exLogout: 'button[action=examLogout]',
			checkSession: 'button[action=checkSession]',
			sessionCheck: '#sessionCheck',
			// End Exam Papers
            basecon: '#basecon',
            exampcon: '#examsearch',
            myacccon: '#myaccCon',
            advanceSearchBtn: '#advanceSearchBtn',
            
            oldTabIndex: -1
        },
        
        //        /* Routes to enable the use of browser's back button and navigating using url
        //         * (Removed due to the lack of time)
        //         * (@author : Justina Lee */
        //        routes:{
        //            'home' : 'goHomePage',
        //            'bookmarked' : 'goBookMarkedPage',
        //            'openinghours/term' : 'goOpeningHoursPage',
        //            'contactus' : 'goContactUsPage',
        //            'libraryupdates' : 'goLibraryUpdatesPage'
        //            'eresources' : 'goEResourcespage',
        //            'advsearch' : 'goAdvanceSearchPan'
        //        },
        /******************************************************************************/
        control:{  
            announcements:{
				getAnnouncements: 'loadAnnouncements'
			},
            bookMarkedButton:{
                tap: 'goBookMarkedPage'
            },
            homeButton:{
                tap: 'goHomePage'
            },
            mainPanel:{
                activeitemchange : 'onChangeTab'
            },
            mainBackButton:{
              tap: 'goTabBack'  
            },
            openingHoursButton: {
                tap: 'goOpeningHoursPage'
            },
            contactUsButton:{
                tap: 'goContactUsPage'
            },
            libraryUpdatesButton:{
                tap: 'goLibraryUpdatesPage'
            },
            moreList:{
                itemtap: 'goPage'
            },
            mainexampaperBtn:{
                tap: 'goExamPaperpage'
            },
            mainmyaccBtn:{
                tap: 'goMyAccpage'
            },
            eResourcesButton:{
                tap: 'goEResourcespage'
            },
			mainNewArrivalsBtn:{
                tap: 'goNewArrivalsPage'
            },
            advanceResultButton:{
                tap: 'goAdvanceSearchPan'
            },
			// Citation:{
				// tap: 'goCitationPage'
			// },
			// LibraryVideos:{
				// tap: 'goLibraryVideosPage'
			// },
			mainAddResourcesBtn:{
				tap: 'goAddResourcespage'
			},
			floorplansbtn:{
				tap: 'goFloorPlanspage'
			},
			exLogin: {
				tap: 'goExamSearchpage'
			},
			exLogout: {
				tap: 'examLogout'
			},
			checkSession: {
				tap: 'checkSession'
			},
			// My account
			MALogin: { tap: 'goMyaccmain' },
			MALogout: { tap: 'goMyAccLogin' },
			MALoan: { tap: 'goMyAccLoan' },
			MAReservation: { tap: 'goMyAccReservation' },
			MARenew: { tap: 'doRenew' },
			// My account end
			RandomClick: { tap: 'getRandomFive' }
        }
    },
    /*
|--------------------------------------------------------------------------
| goBookMarkedPage (@author : Justina Lee)
|--------------------------------------------------------------------------
|
| This function is triggered when the user tap on the bookmarked module
| button located at the top right corner.
|    
| If the bookmarked store is not empty, maximum of 10 items are retrieved
| and added to the bookmarkedMemory store which is then displayed in a list.
| Else if the store is empty, the load more text is changed to "No Bookmarks"
|
| If there are exactly 10 items in the store, the load more text is changed to
| "No More Records".
|
*/
    goBookMarkedPage: function(){
        var ctrl = this;
        
        //refresh list if the current page is the bookmarked page.
        var view = this.getNavView();
        var itemId = view._activeItem._itemId;
        if(itemId == 'bookmarkedView'){
            return;
        }
        
        var previousPage = ctrl.showMask();
        
        var task = Ext.create('Ext.util.DelayedTask', function(){
            var bmStore = Ext.getStore('BookMarked');
            var bmMemoryStore = Ext.getStore('BookMarkedMemory');         
            var bmController = ctrl.getApplication().getController('BookMarked')
            var bmCount = bmStore.getCount();
            var mainView = ctrl.getBookMarkedMainView();
            
            bmMemoryStore.removeAll();  
            
            if(mainView != null){
                mainView.destroy();
            }
        
            ctrl.pushView('Book-Marked!', 'bookmarkedpage');
        
            //add load more cmp
            var listPaging = ctrl.getBookMarkedListPaging();
            listPaging.addLoadMoreCmp();
        
            if(bmCount != 0){
                //retrieve 10 items from localStorage
                var retrieveItems = bmStore.getRange(0, 9);        
                bmMemoryStore.add(retrieveItems);
            }else{
                //change loadMore text to 'No Bookmarks'
                bmController.removeLoadMoreText('- No Bookmarks -');
            }                       
        
            var memoryCount = bmMemoryStore.getCount();
            if (bmCount == memoryCount && bmCount != 0){
                //change loadMore text to 'no more records'
                bmController.removeLoadMoreText('No More Records');
            }
            
            ctrl.hideMask(previousPage);  
        });
        task.delay(1);
    },
    /*
|--------------------------------------------------------------------------
| goHomePage (@author : Justina Lee)
|--------------------------------------------------------------------------
|
| This function is triggered when the user tap on the home button at the top
| right corner.
|
*/
    goHomePage: function(){
        var ctrl = this;
        var previousPage = ctrl.showMask();
        
        var task = Ext.create('Ext.util.DelayedTask', function(){
            ctrl.resetHomePage();
            ctrl.resetOpeningHoursPage();
            
            ctrl.hideMask(previousPage);
        });
        
        task.delay(1);
    },
    /*
|--------------------------------------------------------------------------
| resetHomePage (@author : Justina Lee)
|--------------------------------------------------------------------------
|
| Set the home tab panel's active item index as 0 (Search tab)
| Reset the pressed segmented button at the home page.
| Reset the navigation view.
|
*/
    resetHomePage: function(){
        var mainTabPanel = this.getMainPanel();        
        if(mainTabPanel.activeItemIndex !=  0){
            mainTabPanel.setActiveItem(0);
        }
        
        this.resetHomeSegBtn();
        
        var view = this.getNavView();
        view.reset();
    },
    /*
|--------------------------------------------------------------------------
| resetOpeningHoursPage (@author : Justina Lee)
|--------------------------------------------------------------------------
|
| Reset the pressed segmented button at the opening hours page.
| Set the term opening hours panel as active item.
|
*/
    resetOpeningHoursPage: function(){
        var ohSegBtn = this.getOhSegmentedBtn();
        if(typeof ohSegBtn != 'undefined'){
            ohSegBtn.setPressedButtons([0]);
        
            var ohMainPanel = this.getOhMainPanel();
            ohMainPanel.setActiveItem(0);
        }
    },
    /*
|--------------------------------------------------------------------------
| goOpeningHoursPage (@author : Justina Lee)
|--------------------------------------------------------------------------
|
| Triggers the getCurrentOpeningHours function in OpeningHours controller
| to check which openinghours tab to show the user.
|
*/
    goOpeningHoursPage: function(){
        var ctrl = this;
        var openingHrsCtrl = this.getApplication().getController('OpeningHours');
        
        var backBtn = this.getMainBackButton();
        backBtn.setHidden(true);
        
        ctrl.showMask();
                            
        var task = Ext.create('Ext.util.DelayedTask', function(){
            openingHrsCtrl.getCurrentOpeningHours();  
        });
        task.delay(1);
    },
    /*
|--------------------------------------------------------------------------
| goContactUsPage (@author : Lim Yi Le)
|--------------------------------------------------------------------------
|
| This function is triggered by tapping on the ContactUs tab in the Home view
| and transits the application to the ContactUs view.
|
*/
    goContactUsPage: function(){     
        var ctrl = this;
        var previousPage = ctrl.showMask();
        
        var backBtn = this.getMainBackButton();
        backBtn.setHidden(true);
        
        var task = Ext.create('Ext.util.DelayedTask', function(){
            ctrl.pushView('Contact Us', 'contactuspage');
            ctrl.resetHomeSegBtn();
            ctrl.hideMask(previousPage);
        });
        task.delay(1);
    },
    /*
|--------------------------------------------------------------------------
| goLibraryUpdatesPage (@author : Lim Yi Le)
|--------------------------------------------------------------------------
|
| This function is triggered by tapping on the LibraryUpdates tab in the Home view
| and transits the application to the LibraryUpdates view, loading the LibraryUpdates store.
|
*/
    goLibraryUpdatesPage: function(){     
        var ctrl = this;
        var previousPage = ctrl.showMask();
        
        var backBtn = this.getMainBackButton();
        backBtn.setHidden(true);
        
                            
        var task = Ext.create('Ext.util.DelayedTask', function(){
            var luStore = Ext.getStore('LibraryUpdates');
            ctrl.pushView('Library Updates', 'libraryupdatespage');
        
            luStore.load({
                callback:function(){
                    ctrl.hideMask(previousPage);
                }
            });        
            ctrl.resetHomeSegBtn();
        });
        task.delay(1);
    },
    
    /*
|--------------------------------------------------------------------------
| onChangeTab (@author : Justina Lee)
|--------------------------------------------------------------------------
|
| Triggered when user tap on the bottom tab
|
*/  
    onChangeTab:function(tabPanel, tab, oldTab){
        var backBtn = this.getMainBackButton();
        
        //set the value of oldtabindex for the back button function
        this.oldTabIndex = tabPanel.getInnerItems().indexOf(oldTab);        
        
        var navView = this.getNavView();
        if(tabPanel.getInnerItems().indexOf(tab) != 0){
            backBtn.setHidden(false);
        }else{
            backBtn.setHidden(true);
        }        
        
        
        //get Search Controller
        var mainController = MajorProjectSenchaTouch.app.getController('Main');
                    
        /*
        |--------------------------------------------------------------------------
        | (@author : Joanna Tan)
        |--------------------------------------------------------------------------
        |
        | This will call the goExamPaperpage in the Main controller and
        | redirect the user to TP eExam Paper website
        |
        */
        // if(tab.config.title == 'Exam Paper'){
            //get exampaper container ref in Main controller
            // var con = mainController.getExampcon();
            //Show a message to tell the user that they are being redirected
            // con.setMasked({
                // xtype: 'loadmask',
                // indicator: false,
                // message: MajorProjectSenchaTouch.app.redirectExamPMsg 
            // });
                    
            //set a timer to redirect the user and change the message
            // setTimeout(function() {
                //Show a message to tell the user that they are redirected
                // con.setMasked({
                    // xtype: 'loadmask',
                    // indicator: false,
                    // message:MajorProjectSenchaTouch.app.redirectedExamPMsg 
                // });
                // mainController.goExamPaperpage();
            // }, 1000); 
        // }
                
        /*
        |--------------------------------------------------------------------------
        | (@author : Joanna Tan)
        |--------------------------------------------------------------------------
        |
        | This will call the goMyAccPage in the Main controller and
        | redirect the user to TP My Account website
        |
        |
        */
		// Comment out by Chee Hwa
		/*
        if(tab.config.title == 'My Account'){
            // get my account container ref in Main controller
            var myAccCon = mainController.getMyacccon();
                    
            // Show a message to tell the user that they are being redirected
            myAccCon.setMasked({
                xtype: 'loadmask',
                indicator: false,
                message: MajorProjectSenchaTouch.app.redirectToAccMsg 
            });
                    
            // set a timer to redirect the user and change the message
            setTimeout(function() {
                // Show a message to tell the user that they are redirected
                myAccCon.setMasked({
                    xtype: 'loadmask',
                    indicator: false,
                    message: MajorProjectSenchaTouch.app.redirectedToAccMsg
                });
                mainController.goMyAccpage();
            }, 1000); 
        }
		*/
    },
    
/*
|--------------------------------------------------------------------------
| goTabBack (@author : Justina Lee)
|--------------------------------------------------------------------------
|
| Triggered when the tab's back button is tapped
|
*/
    goTabBack: function(){
        var previousIndex = this.oldTabIndex;
        var mainTabPanel = this.getMainPanel(); 
        
        mainTabPanel.setActiveItem(previousIndex);
    },
    /*
|--------------------------------------------------------------------------
| goPage (@author : Justina Lee)
|--------------------------------------------------------------------------
|
| Navigation of the list in the "More" tab.
|
*/
    goPage: function(list, index, item, record) {
        var xindex = record.get('xindex');
        
        switch(xindex){
            case 1:
                this.goLibraryUpdatesPage();
                break;
			case 2:
				this.goFloorPlanspage();
				break;
            case 3:
                this.goOpeningHoursPage();
                break;
            case 4:
                this.goContactUsPage();
                break;
			case 5:
				this.goSpinMePage();
				break;
        } 
    },
    /*
|--------------------------------------------------------------------------
| pushView (@author : Justina Lee)
|--------------------------------------------------------------------------
|
| Set the title of the navigation bar and push the page into the navigation
| view.
|
*/  
    pushView: function(setTitle, setXtype){
        var view = this.getNavView();
        
        view.push({
            title: setTitle,
            xtype: setXtype
        })
    },
    /*
|--------------------------------------------------------------------------
| resetHomeSegBtn (@author : Justina Lee)
|--------------------------------------------------------------------------
|
| Set the first segmented button (Home) as the pressed button.
|
*/  
    resetHomeSegBtn: function(){
        var homeSegBtn = this.getHomeSegmentedBtn(); 
        
        if(typeof homeSegBtn != 'undefined'){
            homeSegBtn.setPressedButtons([0]);
        }
    },
    /*
|--------------------------------------------------------------------------
| showMask (@author : Justina Lee)
|--------------------------------------------------------------------------
|
| Get the current item in the navigation view and set the loading mask.
| Return the current item as previousPage.
|
*/  
    showMask: function(){
        var view = this.getNavView();
        var previousPage = view._activeItem;
        
        previousPage.setMasked({
            xtype: 'loadmask',
            message: 'Please wait...'
        });
        
        return previousPage;
    },
    
    /*
|--------------------------------------------------------------------------
| hideMask (@author : Justina Lee)
|--------------------------------------------------------------------------
|
| Hide the loading mask of the page.
|
*/  
    hideMask: function(previousPage){        
        previousPage.setMasked(false);
    },
    
    /*
|--------------------------------------------------------------------------
| applyNavUrl (@author : Justina Lee)
|--------------------------------------------------------------------------
|
| Updates the url to the correct route fragment so it always matches the app's
| current state.
|
*/  
    
    applyNavUrl: function(urlLink){
        this.getApplication().getHistory().add(new Ext.app.Action({
            url: urlLink
        }), true);  
    },
    
    
    /*
|--------------------------------------------------------------------------
| goAdvanceSearchPan (@author : Joanna Tan)
|--------------------------------------------------------------------------
|
| This function is triggered when the user tap on the Advance
| Search Button at the Home page. 
|
| It will navigate the user to the Advance Search Page 
| whereby the user will enter their search condition   
|
*/
    goAdvanceSearchPan: function(){
        var ctrl = this;
        var previousPage = ctrl.showMask();
       
        var task = Ext.create('Ext.util.DelayedTask', function(){
            ctrl.pushView('Advanced Search', 'advancepage');
            ctrl.hideMask(previousPage); 
            
            ctrl.applyNavUrl('advsearch');
        });
        task.delay(1);
    },
        
    /*
|--------------------------------------------------------------------------
| goEResourcespage (@author : Joanna Tan)
|--------------------------------------------------------------------------
|
| This function triggers when the user taps on the eResource button at the
| home page. The user will be directed to the eResource page.
|
*/
    goEResourcespage: function(){
        var ctrl = this;
        var previousPage = ctrl.showMask();
        
        var task = Ext.create('Ext.util.DelayedTask', function(){
            var mainTabPanel = ctrl.getMainPanel();        
            if(mainTabPanel.activeItemIndex !=  1){
                mainTabPanel.setActiveItem(1);
            }
            
            ctrl.hideMask(previousPage);  
            
            ctrl.applyNavUrl('eResources');
        });
        task.delay(1);
    },
    
            
/*----------------------------------------------------------------------------------------------------------------------------------------------------
| methods for exam papers module (@author : Sean Yow)
----------------------------------------------------------------------------------------------------------------------------------------------------*/

    goExamPaperpage: function(){
        var ctrl = this;
        var previousPage = ctrl.showMask();
        
		if(MajorProjectSenchaTouch.app.currentExamUser == "") {
			var task = Ext.create('Ext.util.DelayedTask', function(){
				ctrl.pushView('Exam Papers Login', 'examlogin');
				ctrl.hideMask(previousPage);             
				ctrl.applyNavUrl('exam_login'); 
			});
			task.delay(1);
		}
		else {
			var task2 = Ext.create('Ext.util.DelayedTask', function(){
				ctrl.pushView('Exam Paper Search', 'examsearch');
				ctrl.hideMask(previousPage);
				ctrl.applyNavUrl('exam_search'); 	
			});
			task2.delay(1);
		}
	},

	goExamSearchpage: function(currentExamUser){
		var user = Ext.ComponentQuery.query('#userfieldexam')[0].getValue();
		var pass = Ext.ComponentQuery.query('#passfieldexam')[0].getValue();
		var ctrl = this; 
		
		if(user == "" || pass == ""){
			Ext.Msg.show({title:'Error', message: 'Empty username or password.'});
		}
		else
		{
			if(currentExamUser != "") {
				Ext.Ajax.request({
					url: 'index.php/myaccount/doLogin',
					method: 'post',
					params: {
						userName: user,
						userPassword: pass
					},	
					success: function(response) {
						if(response.responseText == "Y" || response.responseText == "E") { 
							ctrl.pushView('Exam Paper Search', 'examsearch');
							ctrl.applyNavUrl('exam_search');
						}
						else if(response.responseText == "N") {
							Ext.Msg.show({title:'Error', message: 'Wrong username or password.'});
						}
						else {
							Ext.Msg.show({title:'Error', message: 'Something is wrong.'});
						}
					},
					failure: function(response) {
						Ext.Msg.show({title:'Error', message:'Server Error.'});
					}
				});	
				Ext.Ajax.request({ // Retrieve session
					url: 'index.php/myaccount/getSession',
					method: 'post',
					params: {
						userName: user
					},
					success: function(response) {
						MajorProjectSenchaTouch.app.currentExamUser = response.responseText;
					},
					failure: function(response) { // Unable to retrieve session
						Ext.Msg.show({title:'Error', message:'Server Error.'});
					}
				});
			}
			else {
				ctrl.pushView('Exam Paper Search', 'examsearch');
				ctrl.applyNavUrl('exam_search');
			}
		}
    },
	
	examLogout: function(){
		MajorProjectSenchaTouch.app.currentExamUser = "";
        var ctrl = this;
        var previousPage = ctrl.showMask();
        
        var task = Ext.create('Ext.util.DelayedTask', function(){
            ctrl.resetHomePage();
            ctrl.resetOpeningHoursPage();
            
            ctrl.hideMask(previousPage);
        });
        
        task.delay(1);
    },
	   
        // var con = this.getNewarrivalspage();
        // con.setMasked({
            // xtype: 'loadmask',
            // message: 'Please wait...'
        // });
/*----------------------------------------------------------------------------------------------------------------------------------------------------
| end methods for checking Exam Papers session (@author : Sean Yow)
----------------------------------------------------------------------------------------------------------------------------------------------------*/

	goNewArrivalsPage: function(){	
        var scope = this;
        //get store
        var resultInfoStore = Ext.getStore('ResultsInfo');
        var resultStore = Ext.getStore('Results');
        
        //empty the store first
        resultInfoStore.removeAll();
        resultStore.removeAll();
        
        var searchBtn = scope.getSearchButton();
        
        //load the store
        resultInfoStore.load({
            callback: function(records, operation, success) {
                // the operation object contains all of the details of the load operation                        
                var setnumber = '';
                var numentries = '';
                var numrecords = '';
                resultInfoStore.each(function(record){
                    setnumber = record.get('setnumber');
                    numentries = record.get('numentries');
                    numrecords = record.get('numrecords');
                });
                
                //check if there is no records found. Show a pop up message if no records found. 
                // if(numentries == '0'){
                    // Ext.Msg.alert(MajorProjectSenchaTouch.app.noMatchFoundTitle,  MajorProjectSenchaTouch.app.noMatchFoundBody);
                    // //hide the loading mask
                    // con.setMasked(false);
                    // //enable the search button
                    // searchBtn.setDisabled(false);
                // }
                // else if(numentries == ''){
                    // Ext.Msg.alert(MajorProjectSenchaTouch.app.errorEncounterTitle,MajorProjectSenchaTouch.app.errorEncounterBody);
                    // con.setMasked(false);
                    // searchBtn.setDisabled(false);
                // }
                // else{
                    //get the result range (start)
                    var nextstartresultvar = resultInfoStore.getAt(0).get('currentstart');
                    //get the result range (end)
                    var nextendresultvar = resultInfoStore.getAt(0).get('currentend');
                    //get the number of entries
                    var getmaxnumberrecord = resultInfoStore.getAt(0).get('numentries');
                    //get the search keyword
                    var searchkw = resultInfoStore.getAt(0).get('keyword');
                  
                    var newset = '';
                    if(getmaxnumberrecord <10){
                        //set search condition (setnumber, page (1), sortby(year), numberofrecordstoretrieve(getmaxnumberrecord)) [split by U5R]
                        newset = setnumber + 'U5R1' + 'U5RYearU5R' + getmaxnumberrecord;
                    }
                    else{
                        //set search condition (setnumber, page (1), sortby(year), numberofrecordstoretrieve(10)) [split by U5R]
                        newset = setnumber + 'U5R1' + 'U5RYearU5R10';
                    }
                
                    if(setnumber == ""){
                    //do nothing
                    }
                    else{
                        resultStore.load({
                            url: MajorProjectSenchaTouch.app.serverUrl +'NewArrivals/retrieveSortList/' + newset //retrieveList
                        }); 
                    }
                    //hide the loading mask
                    // con.setMasked(false);
                    //show the result page
                    // scope.pushView('Search Result', 'newarrivalspage');
                    
                    //get the prev page button
                    // var prevPageBtn = scope.getPrevResultsBtn();
                    
                    //set and display (result range)
                    var displaytext = 'Result ' + nextstartresultvar + ' - ' + nextendresultvar + ' of ' + getmaxnumberrecord;
                    var resultRangeBtn = scope.getResultRangeButton();
                    resultRangeBtn.setHtml(displaytext);
          
                    //disable the prev page button if the start result range is 1
                    if(nextstartresultvar == 1){
                        // prevPageBtn.setDisabled(true);
                    }
                    else{
                        // prevPageBtn.setDisabled(false);
                    }
                    
                    //set and display (results found for keyword)
                    var pushtext = 'We found ' + numrecords + ' items(s) matching your search for ' + searchkw;
                    var resultSummaryBtn = scope.getSearchButton();
                    resultSummaryBtn.setHtml(pushtext);
                    
                    // searchBtn.setDisabled(false);

				   
						

               // }
            },//callback
            url: MajorProjectSenchaTouch.app.serverUrl +'NewArrivals/loadNewAList/'
        });
		var ctrl = this;
		var previousPage = ctrl.showMask();
        ctrl.pushView('New Arrivals', 'newarrivalspage');
						ctrl.hideMask(previousPage); 
						
						ctrl.applyNavUrl('newarrivalspage');
		
    },
   
    /*
|--------------------------------------------------------------------------
| goMyAccpage (@author : Joanna Tan)
|--------------------------------------------------------------------------
|
| This function is trigger when the user click on the My Account
| button at the Home Page and at the home tab panel (My Account).
|
| It will open TP library My Account Website in a new window
|
*/
    /*goMyAccpage: function(){
        var ctrl = this;
        var previousPage = ctrl.showMask();
        
        var task = Ext.create('Ext.util.DelayedTask', function(){
            window.open(MajorProjectSenchaTouch.app.tplibMyAccUrl);
            ctrl.hideMask(previousPage);  
        });
        task.delay(1);     
    },	*/	
	goMyAccpage: function(){
        var ctrl = this;
        var previousPage = ctrl.showMask();
        
		if(MajorProjectSenchaTouch.app.currentUser == "") {
			var task = Ext.create('Ext.util.DelayedTask', function(){
				ctrl.pushView('Login', 'myaccountlogin');
				ctrl.hideMask(previousPage);  
				ctrl.applyNavUrl('myAccountLogin');
			});
		}
		else {
			ctrl.pushView('My Account', 'myaccountmain');
			ctrl.applyNavUrl('myaccountmain');
			Ext.Ajax.request({ // Retrieve nameOfUser
				url: 'index.php/myaccount/getName',
				method: 'post',
				params: {
					userName: MajorProjectSenchaTouch.app.currentUser
				},
				success: function(response) { // Successfully retrieve nameOfUser
					Ext.ComponentQuery.query('#nameOfUser')[0].setHtml(response.responseText, false);
				},
				failure: function(response) { // Unable to retrieve nameOfUser
					Ext.Msg.show({title:'Error', message:'Server Error.'});
				}
			});	
			Ext.Ajax.request({ // Retrieve noForLoan
				url: 'index.php/myaccount/getLoanNo',
				method: 'post',
				params: {
					userName: MajorProjectSenchaTouch.app.currentUser
				},
				success: function(response) { // Successfully retrieve noForLoan
					Ext.ComponentQuery.query('#noForLoan')[0].setHtml(response.responseText, false);
				},
				failure: function(response) { // Unable to retrieve noForLoan
					Ext.Msg.show({title:'Error', message:'Server Error.'});
				}
			});
			Ext.Ajax.request({ // Retrieve noForReservation
				url: 'index.php/myaccount/getReservationNo',
				method: 'post',
				params: {
					userName: MajorProjectSenchaTouch.app.currentUser
				},
					success: function(response) { // Successfully retrieve noForReservation
				Ext.ComponentQuery.query('#noForReservation')[0].setHtml(response.responseText, false);
				},
				failure: function(response) { // Unable to retrieve noForReservation
					Ext.Msg.show({title:'Error', message:'Server Error.'});
				}
			});						
		}
        task.delay(1);     
    },
	/*goMyAccMain: function(){
        var ctrl = this;
        var previousPage = ctrl.showMask();
        
        var task = Ext.create('Ext.util.DelayedTask', function(){
            ctrl.pushView('My Account', 'myaccountmain');
            ctrl.hideMask(previousPage);  
			ctrl.applyNavUrl('myaccountmain');
        });
        task.delay(1);     
    },*/
	


	  goAddResourcespage: function(){
        var ctrl = this;
        var previousPage = ctrl.showMask();
       
        var task = Ext.create('Ext.util.DelayedTask', function(){
            ctrl.pushView('Additional resources', 'additionalResourcesView');
            ctrl.hideMask(previousPage); 
            
            ctrl.applyNavUrl('additionalResourcesView');
        });
        task.delay(1);
    },
	

	goFloorPlanspage: function(){
        var ctrl = this;
        var previousPage = ctrl.showMask();
		var backBtn = this.getMainBackButton(); 
        var task = Ext.create('Ext.util.DelayedTask', function(){
            ctrl.pushView('Floor Plans', 'floorplanspage');		  
            ctrl.hideMask(previousPage);             
            ctrl.applyNavUrl('floorplanspage');
        });
		backBtn.setHidden(true);
        task.delay(1);
    },
	
/*----------------------------------------------------------------------------------------------------------------------------------------------------
| methods of My Account module (@author : Chee Hwa)
----------------------------------------------------------------------------------------------------------------------------------------------------*/
	goMyaccmain: function(){ // Button click event
		var user = Ext.ComponentQuery.query('#userfield')[0].getValue(); // Retrieve username
		var pass = Ext.ComponentQuery.query('#passfield')[0].getValue(); // Retrieve password
		var ctrl = this; // Retrieve current page
		var backBtn = this.getMainBackButton(); // Retrieve page's back button
		var previousPage = ctrl.showMask();
		
		if(user == "" || pass == "") { // EmptyField validator
			Ext.Msg.show({title:'Error', message: 'Empty username or password.'});
		}
		else {
			if(MajorProjectSenchaTouch.app.currentUser == "") { // Current session validator
				Ext.Ajax.request({ // Log in
					url: 'index.php/myaccount/doLogin',
					method: 'post',
					params: {
						userName: user,
						userPassword: pass
					},
					success: function(response) { // Successfully log in
						if(response.responseText == "Y" || response.responseText == "E") {
							MajorProjectSenchaTouch.app.currentUser = user;	// Set golbal variable currentUser here
							Ext.ComponentQuery.query('#passfield')[0].setValue(''); // Remove the password for security purposes
							var task = Ext.create('Ext.util.DelayedTask', function(){
								ctrl.pushView('My Account', 'myaccountmain');
								ctrl.hideMask(previousPage);  
								ctrl.applyNavUrl('myaccountmain');
							});
							task.delay(1);
							backBtn.setHidden(true); // Prevent repeated Back button							
							Ext.Ajax.request({ // Retrieve nameOfUser
								url: 'index.php/myaccount/getName',
								method: 'post',
								params: {
									userName: MajorProjectSenchaTouch.app.currentUser
								},
								success: function(response) { // Successfully retrieve nameOfUser
									Ext.ComponentQuery.query('#nameOfUser')[0].setHtml(response.responseText, false);
								},
								failure: function(response) { // Unable to retrieve nameOfUser
									Ext.Msg.show({title:'Error', message:'Server Error.'});
								}
							});	
							Ext.Ajax.request({ // Retrieve noForLoan
								url: 'index.php/myaccount/getLoanNo',
								method: 'post',
								params: {
									userName: MajorProjectSenchaTouch.app.currentUser
								},
								success: function(response) { // Successfully retrieve noForLoan
								
									Ext.ComponentQuery.query('#noForLoan')[0].setHtml(response.responseText, false);
								},
								failure: function(response) { // Unable to retrieve noForLoan
									Ext.Msg.show({title:'Error', message:'Server Error.'});
								}
							});
							Ext.Ajax.request({ // Retrieve noForReservation
								url: 'index.php/myaccount/getReservationNo',
								method: 'post',
								params: {
									userName: MajorProjectSenchaTouch.app.currentUser
								},
								success: function(response) { // Successfully retrieve noForReservation
									Ext.ComponentQuery.query('#noForReservation')[0].setHtml(response.responseText, false);
								},
								failure: function(response) { // Unable to retrieve noForReservation
									Ext.Msg.show({title:'Error', message:'Server Error.'});
								}
							});						
						}
						else if(response.responseText == "N") { // Wrong username or password.
							Ext.Msg.show({title:'Error', message: 'Wrong username or password.'});
						}
						else { // Unable to retrieve anything from server
							Ext.Msg.show({title:'Error', message: 'Server Error.'});
						}
					},
					failure: function(response) { // Unable to Log in
						Ext.Msg.show({title:'Error', message:'Server Error.'});
					}
				});	
			}
			else { // User logged in before
				ctrl.pushView('My Account', 'myaccountmain');
				ctrl.applyNavUrl('myaccountmain');
				backBtn.setHidden(true);
			}
		}
    },
	
	goMyAccLoan: function(){ // Button click event
		MajorProjectSenchaTouch.app.loanArray = []; // Reset the array
		var ctrl = this;
		Ext.Ajax.request({ // Retrieve the current user's loans count
			url: 'index.php/myaccount/getLoanNo',
			method: 'post',
			params: {
				userName: MajorProjectSenchaTouch.app.currentUser
			},
			success: function(response) { // Successfully retrieve number
				if(response.responseText == '0') // if noForLoan == 0, Current user has no loans
					Ext.Msg.show({title:'Message', message:'No Record.'});
				else {						
					var task = Ext.create('Ext.util.DelayedTask', function(){ // push to loan page
						ctrl.pushView('My Loans', 'myaccountrenew');
					});
					task.delay(1);
					Ext.Ajax.request({ // Retrieve all Loans and their information
						url: 'index.php/myaccount/getAllLoan',
						method: 'post',
						params: {
							userName: MajorProjectSenchaTouch.app.currentUser
						},
						success: function(response) {	// Successfully retrieve object
							var loanOutput = JSON.parse(response.responseText); // Convert string into Json
							var output = "";
							
							for (var i=0; i<loanOutput.length;i++) { // Traverse the Json
								var renewInfo = new Array(loanOutput[0+i].docNo[0],		// renewInfo[0] = docNo
								loanOutput[0+i].itemSequence[0],						// renewInfo[1] = itemSequence
								loanOutput[0+i].id[0],									// renewInfo[2] = id
								loanOutput[0+i].itemStatus[0],							// renewInfo[3] = itemStatus
								loanOutput[0+i].onHold[0],								// renewInfo[4] = onHold
								loanOutput[0+i].requested[0]);							// renewInfo[5] = requested
								MajorProjectSenchaTouch.app.loanArray[i] = renewInfo;						
								output += "Due date: " + loanOutput[0+i].dueDate[0]
								+ " Time: " + loanOutput[0+i].dueHour[0]
								+ "<br><b>" + loanOutput[0+i].title[0]
								+ "</b>" + "<br>" + "Renewal(s) done: "+ loanOutput[0+i].renewal[0]
								+ "<button style='float: right; width: 40%' type='button' "
								+ "onclick='myAccountCtrl.doRenew(MajorProjectSenchaTouch.app.loanArray[" + i + "])'>Renew</button>"
								+ "<br>__________________________________________________<br>";
							}
							Ext.ComponentQuery.query('#loanOutput')[0].setHtml(output, false); // paste at html
						},
						failure: function() { // Unable to retrieve from server
							Ext.Msg.show({title:'Error', message:'Server Error.'});
						}
					});
				}
			},
			failure: function(response) { // Unable to retrieve noForLoan
				Ext.Msg.show({title:'Error', message:'Server Error.'});
			}
		});
	},
	// method for testing of cause
	activatebomb: function() {
		Ext.Msg.show({title:'bonjor', message:'baka Error.'});
	},
	
	goMyAccReservation: function() {
		MajorProjectSenchaTouch.app.reservationArray = []; // Reset the array
		var ctrl = this; // Retrieve the current page
		Ext.Ajax.request({ // Retrieve the current user's reservation count
			url: 'index.php/myaccount/getReservationNo',
			method: 'post',
			params: {
				userName: MajorProjectSenchaTouch.app.currentUser
			},
			success: function(response) {
				if(response.responseText == '0') // if noForReservation == 0, Current user has no reservation
					Ext.Msg.show({title:'Message', message:'No Record.'});
				else {				
					var task = Ext.create('Ext.util.DelayedTask', function(){ // push to reservation page
						ctrl.pushView('My Reservations', 'myaccountreservation');
					});
					task.delay(1);
					Ext.Ajax.request({ // Retrieve all reservations and their information
						url: 'index.php/myaccount/getAllReservation',
						method: 'post',
						params: {
							userName: MajorProjectSenchaTouch.app.currentUser
						},
						success: function(response) { // Successfully retrieve object
							var reserveOutput = JSON.parse(response.responseText); // Convert string into Json
							var output = "";
							
							for (var i=0; i<reserveOutput.length;i++) { // Traverse the Json
								var reservationInfo = new Array(reserveOutput[0+i].id[0],	// reservationInfo[0] = id
								reserveOutput[0+i].docNo[0],								// reservationInfo[1] = docNo
								reserveOutput[0+i].itemSequence[0],							// reservationInfo[2] = itemSequence
								reserveOutput[0+i].sequence[0]);							// reservationInfo[3] = sequence
								MajorProjectSenchaTouch.app.reservationArray[i] = reservationInfo;
								output += "<b>" + reserveOutput[0+i].title[0] + "</b>"
								+ "<br>" + reserveOutput[0+i].status[0]
								+ "<br>Request Date: " + reserveOutput[0+i].requestDate[0]
								+ "<br>End Request Date: " + reserveOutput[0+i].endRequestDate[0]
								+ "<button style='float: right; width: 40%' type='button'"
								+ "onclick='myAccountCtrl.cancelReservation(MajorProjectSenchaTouch.app.reservationArray[" + i + "])'>Cancel</button>"
								+ "<br>__________________________________________________<br>";
							}
							
							Ext.ComponentQuery.query('#reserveOutput')[0].setHtml(output, false); // paste at html
						},
						failure: function() { // Unable to retrieve from server
							Ext.Msg.show({title:'Error', message:'Server Error.'});
						}
					});
				}
			},
			failure: function(response) { // Unable to retrieve noForReservation
				Ext.Msg.show({title:'Error', message:'Server Error.'});
			}
		});
	},
	
	goMyAccLogin: function() { // Button click event
		if(MajorProjectSenchaTouch.app.currentUser == "") { // Current session validator
			currentUser = "";
			var ctrl = this;
			var previousPage = ctrl.showMask();        
		
			var task1 = Ext.create('Ext.util.DelayedTask', function(){
				ctrl.pushView('Login', 'myaccountlogin');
				ctrl.hideMask(previousPage);
			});
			task1.delay(1);
			goMyaccmain();
		}
		else { // User logged in already
			MajorProjectSenchaTouch.app.currentUser = "";
			var ctrl = this;
			var previousPage = ctrl.showMask();
		
			var task2 = Ext.create('Ext.util.DelayedTask', function(){
				ctrl.pushView('Login', 'myaccountlogin');
				ctrl.hideMask(previousPage);
			});
			task2.delay(1);
		}
	},
	
	doRenew: function(renewInfo) {
		var ctrl = this;// Retrieve current page
		// renewInfo[3] = itemStatus
		if(renewInfo[3] == "Normal Loan" || renewInfo[3] == "Corp.Member C" || renewInfo[3] == "AV general" || renewInfo[3] == "Instr. Guide" ||
		renewInfo[3] == "Music Scores" || renewInfo[3] == "AV CD" || renewInfo[3] == "Back Periodical" || renewInfo[3] == "On Display L3" ||
		renewInfo[3] == "New Arrivals L2" || renewInfo[3] == "New Arrivals L3") { // Renewal can only be done if Items status is one of the following
			if(renewInfo[4] == "N" && renewInfo[5] == "N") { // Check if there is any reservation made
				Ext.Ajax.request({ // Renew function
					url: 'index.php/myaccount/doRenew',
					method: 'post',
					params: {
						docNo : renewInfo[0],
						itemSequence : renewInfo[1],
						id : renewInfo[2]
					},
					success: function(response) { // data return from server
						var renewResult = JSON.parse(response.responseText); // Convert string to Json
						var dueDate = "";
						var dueHour = "";
						var error = "";
						if(renewResult[0] == 'reply') { // Renew success
							dueDate = renewResult[0].dueDate[0];
							dueHour = renewResult[0].dueHour[0];
							Ext.Msg.show({title:'Done', message:'New due date: ' + dueDate + '<br>New Due Hour: ' + dueHour}); // Pop up
						}
						else if (renewResult[0] == 'error'){ // Renew failure
							console.log(response.responseText);
							error = renewResult[0].error[0];
							Ext.Msg.show({title:'Error', message:error}); // Pop up
						}
						else { // Renew failure
							Ext.Msg.show({title:'Error', message:'Server Error.'});
						}
					},
					failure: function(response) { // Renew failure, reason: no data return from server
						Ext.Msg.show({title:'Error', message:'Server Error.'});
					}
				});
			}
			else { // Renew failure, reason: reserved
				Ext.Msg.show({title:'Error', message:'Item reserved by someone'});
			}
		}
		else { // Renew failure, reason: not renewable
			Ext.Msg.show({title:'Error', message:'Item is not renewable'});
		}		
	},
	
	cancelReservation: function(reservationInfo) {
		var ctrl = this; // Retrieve current page
		Ext.Ajax.request({
			url: 'index.php/myaccount/cancelReservation',
			method: 'post',
			params: { // Cancel reservation function
				id : reservationInfo[0],
				docNo : reservationInfo[1],
				itemSequence : reservationInfo[2],
				sequence : reservationInfo[3]
			},
			success: function(response) { // Cancel success
				if(response.responseText == 'OK')
					Ext.Msg.show({title:'Done', message:'Reservation canceled'});
				else 
					Ext.Msg.show({title:'Error', message:'Server Error.'});		
			},
			failure: function(response) { // Cancel failure, reason: no data return from server
				Ext.Msg.show({title:'Error', message:'Server Error.'});
			}
		});
	},
	
	/*	Development for checking of session at bottom
	checkAccSession: function() {
		var backBtn = this.getMainBackButton();
		if(MajorProjectSenchaTouch.app.currentUser == "")
		{
	        var ctrl = this;
			var task = Ext.create('Ext.util.DelayedTask', function(){
				ctrl.pushView('Login', 'myaccountlogin');
				ctrl.hideMask(previousPage);  
				ctrl.applyNavUrl('myAccountLogin');
				backBtn.setHidden(true);
			});
			task.delay(1);
		}
		else
		{
		    var ctrl = this;
			var task2 = Ext.create('Ext.util.DelayedTask', function(){
				ctrl.pushView('Exam Login', 'myaccountmain');
				ctrl.hideMask(previousPage);  
				ctrl.applyNavUrl('myaccountmain');
				backBtn.setHidden(true);
			});
			task2.delay(1);
		}			
	},
	*/
	
/*----------------------------------------------------------------------------------------------------------------------------------------------------
| end of methods of my account module (@author : Chee Hwa)
----------------------------------------------------------------------------------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------------------------------------------------------------------------------
| methods of Spin Me module (@author : ?)
| How this function going to work
| 1) System retrieve the total index from api
| 2) Using this number, system random 5 different numbers to get the index from the list of result from related categories
| 3) Retrieve all information form the xml and show in page
----------------------------------------------------------------------------------------------------------------------------------------------------*/

	goSpinMePage: function() {
        var ctrl = this;
        var previousPage = ctrl.showMask();        
		var backBtn = this.getMainBackButton(); // Retrieve page's back button
		
        var task = Ext.create('Ext.util.DelayedTask', function(){
            ctrl.pushView('Spin Me', 'spinmepage');
            ctrl.hideMask(previousPage);
			backBtn.setHidden(true); // Prevent repeated Back button
        });
        task.delay(1);				
	},
	// + "<button style='float: right; width: 40%' type='button'"
	// + "onclick='myAccountCtrl.cancelReservation(MajorProjectSenchaTouch.app.reservationArray[" + i + "])'>Cancel</button>"
	
	showAllInSpinMe: function() {
		var total = "";
		for(var i=0; i<200; i++) {
			total += "<button style='width: 100%; border:white' type='button' onclick='spinMeCtrl.getRandomFive(\"openShelfbooks\")'>Open shelf books</button>";
			total += "<button style='width: 100%; border:white' type='button' onclick='spinMeCtrl.getRandomFive(\"novels\")'>Novels</button>";
			total += "<button style='width: 100%; border:white' type='button' onclick='spinMeCtrl.getRandomFive(\"lifestyleBooks\")'>Lifestyle books</button>";
			total += "<button style='width: 100%; border:white' type='button' onclick='spinMeCtrl.getRandomFive(\"featureFilms\")'>Feature films</button>";
			total += "<button style='width: 100%; border:white' type='button' onclick='spinMeCtrl.getRandomFive(\"music\")'>Music</button>";
			if(i==100) {
				total += "<button style='width: 100%; border:white' type='button' selected='selected' onclick='spinMeCtrl.getRandomFive(\"newArrivals\")'>New Arrivals</button>";
			}
			else {
				total += "<button style='width: 100%; border:white' type='button' onclick='spinMeCtrl.getRandomFive(\"newArrivals\")'>New Arrivals</button>";
			}
		}
		Ext.ComponentQuery.query('#spinMeItems')[0].setHtml(total, false); // paste at html
	},
	
	getRandomFive: function(input) {
		Ext.ComponentQuery.query('#middlePanel')[0].setHtml(input, false); // paste at html
		Ext.Ajax.request({
			url: 'index.php/spinme/retrieveItems',
			method: 'post',
			params: { 
				category : input,
			},
			success: function(response) { 
				console.log(response);
			},
			failure: function(response) {

			}
		});
	},
	
/*----------------------------------------------------------------------------------------------------------------------------------------------------
| end of methods of Spin Me module
----------------------------------------------------------------------------------------------------------------------------------------------------*/	

/*----------------------------------------------------------------------------------------------------------------------------------------------------
| methods of Announcements module (@author : Huiyi)
----------------------------------------------------------------------------------------------------------------------------------------------------*/
	
	  loadAnnouncements: function()
    {   
      	var scope = this;
		//get the store
        var announcementsInfoStore = Ext.getStore('AnnouncementsInfo');
		
		//clear the store
        announcementsInfoStore.removeAll();
		
		//set a loading mask to let user know their request is being process'
        // var con = this.getAdvabasecon();
        // con.setMasked({
            // xtype: 'loadmask',
            // message: 'Please wait...'
        // });
		
		//load the store
		announcementsInfoStore.load({
			// callback: function(records, operation, success) {
			
			// console.log('asd');
			//hide the loading mask
            // con.setMasked(false);
			// console.log('asfsd');
			//show the result page
            // scope.pushView('Announcements', 'basicsearchpanel');

			// },//callback
            url: MajorProjectSenchaTouch.app.serverUrl +'announcements/getAnnouncements/'
		
		
		});
    },
/*----------------------------------------------------------------------------------------------------------------------------------------------------
| end of methods of announcements module (@author : Huiyi)
----------------------------------------------------------------------------------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------------------------------------------------------------------------------
| method for checking Exam Papers session (@author : Sean Yow)
----------------------------------------------------------------------------------------------------------------------------------------------------*/
	
    checkSession: function() {
		var backBtn = this.getMainBackButton();
		// if(MajorProjectSenchaTouch.app.currentExamUser == "")
		// {
	        // var ctrl = this;
			// var task = Ext.create('Ext.util.DelayedTask', function(){
				// ctrl.pushView('Exam Login', 'examlogin');
				// backBtn.setHidden(true);
			// });
			// task.delay(1);
		// }
		// else
		// {
		    var ctrl = this;
			var task2 = Ext.create('Ext.util.DelayedTask', function(){
				ctrl.pushView('Exam Search', 'examsearch');
				backBtn.setHidden(true);
			});
			task2.delay(1);
		// }			
	},

/*----------------------------------------------------------------------------------------------------------------------------------------------------
| end of method for checking Exam Papers session (@author : Sean Yow)
----------------------------------------------------------------------------------------------------------------------------------------------------*/

	
});

